home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / DNA / DNAV1I6.sit / DNAV1I6 / ARTICLE.007 < prev    next >
Text File  |  1993-12-02  |  9KB  |  130 lines

  1.  
  2.            x86 Assembly Language Tutorial [2/?] by Horsepowr
  3.                             Written for DnA
  4.  
  5.  
  6.        This article is the second in a series of documents of which aim to 
  7. teach the novice, or experienced high-level language programmer x86 assembly
  8. language.  The previous article covered hexidecimal notation of binary 
  9. numerics and the representative decimal equilvalents.  This is a topic that
  10. is neccesary to wholly comprehend to procede further in this tutorial.  If you
  11. do not grasp the concept of hexadecimal notation, please read my previous
  12. article, or obtain some other instruction on this topic.  This passage will
  13. cover the registers of the 8086/8088 microprocessor.  The 80186, 80286, 80386, 
  14. 80486, and P5 based machines are all downwardly compatible with the 8086's 
  15. architechture.  There are many advanced and extended registers on these higher 
  16. level microprocessors, which we'll get into as the topic progresses to 80386
  17. protected mode programming.
  18.  
  19.         The 8086 is a 16 bit processor, designed to operate on a 16 bit bus.
  20. The only factor that separates the 8086 and the 8088 microprocessors are the
  21. bus widths, as the 8088 is intended for an 8 bit bus.  To the programmer, they
  22. are identical, much as the 80386DX and 80386SX are.  They only differ at the 
  23. hardware level, which is taken care of by the controllers built in to the 
  24. motherboard and the processor itself, and are not accessible to the programmer.  
  25. All microprocessors have registers, which are areas within the microprocessor 
  26. which handle data, and can be directly addressed and accessed by the 
  27. programmer to give the processor data with which to calculate or manipulate, 
  28. or for the processor to return resultant values for the program to handle.  
  29. Think of a register as the processor's "hands".  You must put data into the 
  30. processor's "hands" for it to do anything with, and after it is done it 
  31. "hands" it back to the programmer.  With a human being, hands are very 
  32. versitile, not so with a microprocessor.  Many registers have specific 
  33. purposes, and while some may be used for generic duties as well, some do not 
  34. allow you to alter or access them without going through a great deal of effort, 
  35. and others require a specific register to perform a duty, and no other 
  36. register may be substituted.
  37.  
  38.         There are 4 general purpose registers on the 8086, which can be used
  39. for basic instructions that do not require data to be placed in a specific 
  40. register.  These are the Accumulator register (AX), Base register (BX), Count
  41. register (CX), and Data register (DX).  The AX, BX, CX, and DX registers are
  42. all 16 bits large, and can be given 16 bits as a whole by indicating their
  43. full name (AX, BX, CX, and DX) or can be given 8 bit items of data by 
  44. splitting them up into high and low registers (AH/AL, BH/BL, CH/CL, DH/DL).
  45. For example, lets say you want to pass the number 0A724h as a parameter.  
  46. Since this is a 16 bit number, you would want to put it as a whole into the
  47. AX register, but you could also insert 0A7h into AH and 24h into AL to acheive
  48. the same result.  If you only need to pass an 8 bit number you can use only 
  49. a high or low register, for example, if the parameter was only 0F2h, then you 
  50. could fit the entire number into the AL register to save the AH register for
  51. later use.  Registers are your most powerful tools when programming, as the
  52. data in a register is already in the processor, it doesn't have to travel 
  53. along the slow bus as when dealing with data in memory.  If you can perform
  54. an entire calculation strictly within the registers, the difference in speed
  55. between that approach and one which access memory only once or twice is often 
  56. more than tenfold.  This direct access to the registers is one of the most
  57. powerful benefits of programming in assembly language.  One thing to remember
  58. about splitting up the 16 bit general registers is the fact that unless you
  59. phsyically put zeros into the adjacent register (i.e. AH-AL) the twin register
  60. contains relevant data.  This can cause concern when a procedure is expecting
  61. data in the full AX register, and since the number you have to pass is only
  62. 8 bits, you put it in the AL register.  If you fail to clear out the AH 
  63. register, it will contain data and will not pass your inteneded 8 bit number,
  64. instead you will get a garbage 16 bit number that will wreak havok with your
  65. program.  For example, Procedure XYZ is expecting a value in the CX register.
  66. Since your parameter is 72h, you place it in the CL register, unbeknownst to
  67. you that the CX register contained 0FF23h before, the CX register will now
  68. contain 0FF72h, as you only modified CL, not CH, so CH remains the same.
  69.         
  70.         The other Registers are more specific in purpose, and do not share
  71. the ability to be split into seperate halves like the general registers.  
  72. They are split up into sections: Index registers, Segment registers, Pointer
  73. registers, Index registers, and Control registers.  All of these registers
  74. are 16 bits wide on the 8086, some of which are expanded to 32 or 64 bits on 
  75. later processors.  The Index registers are the Stack Index register (SI) and 
  76. the Data Index register (DI).  These registers are used to provide a means
  77. for offsetting (adding to a constant) an address (base address, the constant).
  78. The Segment registers contain the address of the current segments (up to 64k
  79. blocks of memory) in use by the processor.  The segment registers consist of
  80. the Code Segment register (CS - contains the base address of the current 
  81. segment of code being executed by the processor), Stack Segment register (SS - 
  82. contains the base address of the Stack in use), Data Segment register (DS -
  83. contains the base address of the current segment of main data), and the Extra
  84. Segment register (ES - contains the base address of the secondary data 
  85. segment).  The pointer registers are typically used as placeholders within the 
  86. stack but may be used for other purposes, they are made up of the Base Pointer
  87. register (BP) and the Stack Pointer register (SP).  Finally there remains the
  88. the Control registers.  They are the Flags register (FLAGS) and the 
  89. Instruction Pointer register (IP - It contains the offset within the code
  90. segment of the next instruction for the processor to execute.  It is not used 
  91. in the same manner as the other pointer registers so it is classified as a 
  92. control register because it cannot be modified directly and cannot be used for 
  93. an alternate use).  The Flags register contains a bitfield of status 
  94. indicators which are:
  95.                                                                      more>>>>
  96. _________________________________________________________________________________
  97. |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |
  98. | xx | xx | xx | xx | OF | DF | IF | TF | SF | ZF | xx | AF | xx | PF | xx | CF |
  99. |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |
  100. ---------------------------------------------------------------------------------
  101.   15   14   13   12   11   10    9    8    7    6    5    4    3    2    1    0
  102.  
  103.         xx- denotes flag bits reserved for later use by Intel, some of which
  104.             have been implemented on the 80186-80486.
  105.  
  106. The value of the flag bits indicate a condition or state of the processor, or
  107. signal a result of an operation.  They are used by comparison and string 
  108. operations which will be explained in later issues.  The full names for the 
  109. flags, in ascending bit order (Least significant bit (LSB) -> Most significant 
  110. bit (MSB) ) are: Carry flag (Indicates a math operation generated a carry), 
  111. Parity flag (Contains the parity of an instruction), Auxiliary flag (Used with
  112. decimal arithmetic operations), Zero flag (Set when the result of a previous
  113. instruction equated to zero), Sign flag (Indicates a negative result), Trap
  114. flag (Used in debugging work), Interrupt Enable flag (Allows or disallows
  115. maskable interrupts), Direction flag (Sets the direction of order for string
  116. operations), and the Overflow flag (Indicates the result of an operation was
  117. to large to fit in the specifed destination register).  
  118.  
  119.         Now that you are completely confused with all of the information 
  120. you're probably feeling is irrelivant, we come to the end of this article.  
  121. Readers of the first article will note I promised to discuss the use of memory 
  122. on the x86 platform, but I have now realized that this topic is an article 
  123. within itself, so that will be the subject of my next article.  Stay tuned!  
  124. If you have any questions, feel free to channel any feedback, requests, hate 
  125. mail, or whatever through DnA, or direct to me at my system: 
  126.         
  127.            The Finish Line (714) 572-8696 ZyXEL 16.8 / v.32bis
  128.  
  129.                       Hasta -HP       ƒƒƒtURB@ƒƒƒ
  130.